const getDown = function(file, values,back) {
	// console.log('valuesvalues',values);
	let a = uni.getStorageSync('downloading_list');
	
	let downloadTask = uni.downloadFile({
		url: file,

		success(res) {
			// console.log('resssssssssssssssssssss1111111111111111111',res);
			let file = uni.getStorageSync('downloading_list');
			let file1 = uni.getStorageSync('downloaded');
			let Array = [];
			if (res.statusCode == 200) {
				const index = file.findIndex((item,index) => {
					return item.id == values.id;
				});
				let arr = file.splice(index,1);
				// console.log('arrrrrr',arr);
				arr[0].file_url = res.tempFilePath;
				if (!file1) {
					Array.push(arr[0]);
					uni.setStorageSync('downloaded', Array);
				} else {
					Array = file1;
					Array.push(arr[0]);
					uni.setStorageSync('downloaded', Array);
				}
				// uni.setStorageSync('downloaded', arr);
				if (arr.length == 0) {
					uni.removeStorageSync('downloading_list');
				} else {
					uni.setStorageSync('downloading_list', file);
				}
				
				back();
			}
		}
	});
	// console.log('11111111',downloadTask);
	let arr = [];
	if (!a) {
		arr.push({
			downloadTask,
			progress:0,
			...values
		});
	} else {
		arr = a;
		arr.push({
			downloadTask,
			progress:0,
			...values
		})
	}
	uni.setStorageSync('downloading_list', arr);
	// downloadTask.onProgressUpdate((res) => {
	// 	let arr6 = uni.getStorageSync('downloading_list');
	// 	const index6 = arr6.findIndex((item,index) => {
	// 		return item.id == values.id;
	// 	});
	// 	arr6[index6].progress = res.progress;
	// 	uni.setStorageSync('downloading_list', arr6);
	// 	back();
	// 	// this.listLoading[index].progress = res.progress;
	// });
	
	return downloadTask;
}

export default {
	getDown
}